package game.ability;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import game.entity.AbsSprite;
import game.entity.BufferSpriteManager;
import game.entity.Monster;
import game.entity.SpriteManager;
import game.entity.Weapon;
import game.particles.Particle_1;
import game.shared.Constants;

public class Shot  extends AbsAbility{

	AbsSprite source;
	AbsSprite target;
	int  rocketID;
	float delay;
	float timer;
	float speed;
	boolean bAction;
	SpriteBatch sb;
//	AbilityManager abilityManager;

	SpriteManager weaponManager;
	public Shot(AbilityManager abilityManager, SpriteBatch sb, AbsSprite _gunSource, int _rocketID, float _delay, SpriteManager _weaponManager, float _speed, AbsSprite target)
	{
		super();
		this.source = _gunSource;
		this.rocketID = _rocketID;
		this.delay = _delay;
		this.timer = 0;
		this.weaponManager = _weaponManager;
		this.speed = _speed;
		slower = 1;
		this.target = target;
		bAction = true;
		this.sb = sb;
//		this.abilityManager = abilityManager;
	}

	@Override
	public void action() {
		timer = 0;
		bAction = true;
	}
	
	@Override
	public void update() {
		if(!bAction)
			return;
		
		timer += Gdx.graphics.getDeltaTime();
		if(timer >= delay + delay*(1-slower))
		{
			switch(rocketID)
			{
			case Constants.ROCKET_AMMUNITION:
				Weapon rocket = new Weapon((Weapon)BufferSpriteManager.getSpriteBufferByID(BufferSpriteManager.BUFFER_SPRITE_ROCKET_1));
				float a = source.getHeight();
				float b = rocket.getHeight();
				rocket.setPosition(source.getX(), source.getY() + a - b);
				MovingLeft mover = new MovingLeft(speed);
				rocket.setMoving(mover);
				
				AbilityLostHP ability = new AbilityLostHP(Constants.ABILITY_LOSTHP, 5, target);
				rocket.addAbility(ability);
//				AbilityFireUp abilityFireUp = new AbilityFireUp(Constants.ABILITY_FIREUP);
//				abilityManager.add(abilityFireUp);
				weaponManager.add(rocket);
				timer = 0;
				break;
			case Constants.ROCKET_WHITE:
				break;
			}
		}
	}
}
